#Requires AutoHotkey v2.0

;遍历文件夹 GUI的形式
changeLoopFileDir() {
  OnlyInput.fileDir := DirSelect(A_Desktop,2)
  OnlyInput.fixedTip(OnlyInput.fileDir, 2000)
  Send "{Esc}"
}

; 记录鼠标点击的数组
getMousePos() {
  arr := Array()
  foo(ih,vk,sc) {
    CoordMode 'mouse', 'Client'
    MouseGetPos(&x,&y)
    arr.Push(x,y)
    OnlyInput.fixedTip(x . "," . y)
  }  
  OnlyInput.fixedTip("空格键获取鼠标位置`n按Esc完成")
  getClickPos := InputHook("V","{Escape}")
  getClickPos.KeyOpt("{Space}","N")
  getClickPos.OnKeyDown := foo
  Suspend(1)
  getClickPos.Start() 
  getClickPos.Wait()
  Suspend(0)
  OnlyInput.fixedTip("完成", 1500)
  return arr
}

;获取当前光标位置
getCursePos() { 
  A_Clipboard := ""
  WinWaitActive("A")
  arr := getMousePos()
  for i in arr {
    A_Clipboard .= (A_Index = arr.Length ? i : i . ",")
  }
  OnlyInput.fixedTip(A_Clipboard, 2000)
}


;PDF反色
firefoxPDF() {
  send "^+{i}"
  Sleep 1000
  Send "{Tab}"
  Sleep 100
  Send "{#}viewerContainer{Enter}"
  Sleep 200
  send "{Enter}"
  Sleep 1000
  KeyWait("Space", "D")
  Send "filter: invert(100%) contrast(85%){Enter}"
  Sleep 1000
  send "^+{i}"
}

;视频镜像翻转
videoMirrorFlip() {
  send "^+{i}"
  Sleep 1000
  Send "^+c"
  Sleep 1000
  Click(564,344)
  Sleep 1000
  Click(1705,753)
  Send "transform: rotateY(180deg)"
  Sleep 1000
  send "^+{i}"
}

;计算器
eval(Expression) {
  static shell := ComObject("WScript.Shell")
  exec := shell.Exec(A_AhkPath " /ErrorStdOut=UTF-8 *")
  exec.StdIn.Write("#NoTrayIcon`n#Warn All, Off`ntry FileAppend(" Expression ", '*')")
  exec.StdIn.Close()
  out := exec.StdOut.ReadAll()
  A_Clipboard := (out = "" ? "ERROR" : out)
  OnlyInput.fixedTip(A_Clipboard, 2000)
  return A_Clipboard
}

;设置亮度
SetBrightness(CurrentBrightness) {
  OnlyInput.fixedTip("亮度 " CurrentBrightness,2000)
  Run("powershell.exe `"(Get-WmiObject -Namespace root/wmi -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, " CurrentBrightness ")`"",,"Hide")
}

;PostMessage
; PostMessage(0x111, 65303,,, "A.ahk - AutoHotkey")   ;重启
; PostMessage(0x111, 65304,,, "A.ahk - AutoHotkey")   ;编辑
; PostMessage(0x111, 65305,,, "A.ahk - AutoHotkey")   ;挂起
; PostMessage(0x111, 65306,,, "A.ahk - AutoHotkey")   ;暂停
; PostMessage(0x111, 65307,,, "A.ahk - AutoHotkey")   ;退出

ahkReload() {
  MsgBox "Reload"
  Run(A_WorkingDir "\run.ahk")
}

ahkSuspend() {
  DetectHiddenWindows(true)
  SetTitleMatchMode(2)
  PostMessage(0x111, 65305,,, A_WorkingDir "\index.ahk")
  PostMessage(5,,,, A_WorkingDir "\component\toggleCaseConversion.ahk")
}

Enter & CapsLock:: ahkReload
